package roborally.model;

import be.kuleuven.cs.som.annotate.*;

public enum EnergyUnit {
	WS("Ws"), J("J"), KJ("kJ");
	
	private EnergyUnit(String postfix){
		this.postfix = postfix;
	}
	
	private final String postfix;
	
	/**
	 * Return the postfix of the unit.
	 */
	@Basic @Raw @Immutable
	public String getPostfix(){
	  return this.postfix;
	}
	
	/**
	 * the table represents the value of 1 of the unit of the row in the unit on the column
	 * 		Ws		J		kJ
	 * Ws	1		1		1/1000
	 * J	1		1		1/1000
	 * kJ	1000	1000	1
	 * 
	 */
	private final static double[][] unitConversionTable = {	{1,1,1/1000},
																{1,1,1/1000},
																{1000,1000,1}	};
	/**
	 *  Return the value of 1 unit of this EnergyUnit in the other EnergyUnit
	 */
	public double toEnergyUnit(EnergyUnit otherUnit){
		if(otherUnit == null) throw new IllegalArgumentException("The given Unit is not effective.");
	    return unitConversionTable[this.ordinal()][otherUnit.ordinal()];
	}
}
